from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-02-05 14:04:43.628443
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sat, 05, Feb, 2022
Time: 14:04:48
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.9827
Nobs: 558.000 HQIC: -48.4078
Log likelihood: 6545.87 FPE: 7.21885e-22
AIC: -48.6802 Det(Omega_mle): 6.15235e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.351186 0.069329 5.066 0.000
L1.Burgenland 0.106186 0.042154 2.519 0.012
L1.Kärnten -0.110660 0.021906 -5.052 0.000
L1.Niederösterreich 0.192875 0.087633 2.201 0.028
L1.Oberösterreich 0.132502 0.087044 1.522 0.128
L1.Salzburg 0.254432 0.044576 5.708 0.000
L1.Steiermark 0.034530 0.058743 0.588 0.557
L1.Tirol 0.099178 0.047444 2.090 0.037
L1.Vorarlberg -0.070973 0.041936 -1.692 0.091
L1.Wien 0.018136 0.077505 0.234 0.815
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.053923 0.150029 0.359 0.719
L1.Burgenland -0.041561 0.091222 -0.456 0.649
L1.Kärnten 0.040430 0.047405 0.853 0.394
L1.Niederösterreich -0.200410 0.189640 -1.057 0.291
L1.Oberösterreich 0.455492 0.188364 2.418 0.016
L1.Salzburg 0.283490 0.096464 2.939 0.003
L1.Steiermark 0.114125 0.127121 0.898 0.369
L1.Tirol 0.306221 0.102669 2.983 0.003
L1.Vorarlberg 0.022917 0.090750 0.253 0.801
L1.Wien -0.025068 0.167723 -0.149 0.881
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.192974 0.035406 5.450 0.000
L1.Burgenland 0.088701 0.021528 4.120 0.000
L1.Kärnten -0.007526 0.011187 -0.673 0.501
L1.Niederösterreich 0.236311 0.044754 5.280 0.000
L1.Oberösterreich 0.170037 0.044453 3.825 0.000
L1.Salzburg 0.039047 0.022765 1.715 0.086
L1.Steiermark 0.025138 0.030000 0.838 0.402
L1.Tirol 0.081426 0.024230 3.361 0.001
L1.Vorarlberg 0.054982 0.021417 2.567 0.010
L1.Wien 0.120675 0.039582 3.049 0.002
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.119787 0.035411 3.383 0.001
L1.Burgenland 0.043357 0.021531 2.014 0.044
L1.Kärnten -0.013739 0.011189 -1.228 0.219
L1.Niederösterreich 0.168187 0.044760 3.758 0.000
L1.Oberösterreich 0.335307 0.044459 7.542 0.000
L1.Salzburg 0.099779 0.022768 4.382 0.000
L1.Steiermark 0.110100 0.030004 3.670 0.000
L1.Tirol 0.090804 0.024233 3.747 0.000
L1.Vorarlberg 0.061194 0.021419 2.857 0.004
L1.Wien -0.015052 0.039587 -0.380 0.704
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.126919 0.066738 1.902 0.057
L1.Burgenland -0.048628 0.040579 -1.198 0.231
L1.Kärnten -0.045479 0.021087 -2.157 0.031
L1.Niederösterreich 0.136468 0.084358 1.618 0.106
L1.Oberösterreich 0.165700 0.083790 1.978 0.048
L1.Salzburg 0.284570 0.042910 6.632 0.000
L1.Steiermark 0.057997 0.056547 1.026 0.305
L1.Tirol 0.156220 0.045671 3.421 0.001
L1.Vorarlberg 0.094946 0.040368 2.352 0.019
L1.Wien 0.074562 0.074609 0.999 0.318
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.081002 0.052081 1.555 0.120
L1.Burgenland 0.024179 0.031667 0.764 0.445
L1.Kärnten 0.053303 0.016456 3.239 0.001
L1.Niederösterreich 0.190869 0.065832 2.899 0.004
L1.Oberösterreich 0.331628 0.065388 5.072 0.000
L1.Salzburg 0.032971 0.033486 0.985 0.325
L1.Steiermark 0.004285 0.044129 0.097 0.923
L1.Tirol 0.119755 0.035641 3.360 0.001
L1.Vorarlberg 0.066321 0.031503 2.105 0.035
L1.Wien 0.097687 0.058223 1.678 0.093
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.174143 0.062881 2.769 0.006
L1.Burgenland 0.003178 0.038233 0.083 0.934
L1.Kärnten -0.065491 0.019868 -3.296 0.001
L1.Niederösterreich -0.113328 0.079483 -1.426 0.154
L1.Oberösterreich 0.214136 0.078948 2.712 0.007
L1.Salzburg 0.053476 0.040430 1.323 0.186
L1.Steiermark 0.249716 0.053279 4.687 0.000
L1.Tirol 0.498605 0.043031 11.587 0.000
L1.Vorarlberg 0.065525 0.038035 1.723 0.085
L1.Wien -0.076489 0.070297 -1.088 0.277
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.158586 0.069606 2.278 0.023
L1.Burgenland -0.004407 0.042323 -0.104 0.917
L1.Kärnten 0.061987 0.021993 2.818 0.005
L1.Niederösterreich 0.174149 0.087984 1.979 0.048
L1.Oberösterreich -0.065208 0.087392 -0.746 0.456
L1.Salzburg 0.205651 0.044754 4.595 0.000
L1.Steiermark 0.139405 0.058978 2.364 0.018
L1.Tirol 0.057157 0.047633 1.200 0.230
L1.Vorarlberg 0.143856 0.042103 3.417 0.001
L1.Wien 0.132135 0.077815 1.698 0.089
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.395315 0.040682 9.717 0.000
L1.Burgenland -0.003116 0.024736 -0.126 0.900
L1.Kärnten -0.020660 0.012854 -1.607 0.108
L1.Niederösterreich 0.200195 0.051423 3.893 0.000
L1.Oberösterreich 0.238163 0.051077 4.663 0.000
L1.Salzburg 0.034427 0.026157 1.316 0.188
L1.Steiermark -0.018846 0.034470 -0.547 0.585
L1.Tirol 0.088137 0.027840 3.166 0.002
L1.Vorarlberg 0.052010 0.024608 2.114 0.035
L1.Wien 0.037717 0.045480 0.829 0.407
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.035089 0.104311 0.168725 0.134328 0.095797 0.081258 0.030485 0.212647
Kärnten 0.035089 1.000000 -0.025264 0.132422 0.046425 0.086027 0.444253 -0.068430 0.092689
Niederösterreich 0.104311 -0.025264 1.000000 0.308796 0.123693 0.267992 0.065471 0.156187 0.281103
Oberösterreich 0.168725 0.132422 0.308796 1.000000 0.216351 0.294340 0.170546 0.135023 0.237232
Salzburg 0.134328 0.046425 0.123693 0.216351 1.000000 0.124741 0.090299 0.104312 0.129063
Steiermark 0.095797 0.086027 0.267992 0.294340 0.124741 1.000000 0.134299 0.106357 0.029846
Tirol 0.081258 0.444253 0.065471 0.170546 0.090299 0.134299 1.000000 0.063739 0.152690
Vorarlberg 0.030485 -0.068430 0.156187 0.135023 0.104312 0.106357 0.063739 1.000000 -0.003542
Wien 0.212647 0.092689 0.281103 0.237232 0.129063 0.029846 0.152690 -0.003542 1.000000